<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>签约通知</title>
<link rel="stylesheet" href="../css/layui.css">
<link rel="stylesheet" href="../css/modal_l.css">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.css">

<link rel="stylesheet" href="../layui/css/layui.css" media="all">
<script type="text/javascript" src="../layui/layui.js"></script>
<!-- 网页字体库 -->
<link href="http://fonts.googleapis.com/css?family=Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&amp;subset=devanagari,latin-ext"rel="stylesheet">
<link href="http://fonts.googleapis.com/css?family=Tangerine:400,700" rel="stylesheet">
<link href="http://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i&amp;subset=cyrillic,cyrillic-ext,greek,greek-ext,latin-ext,vietnamese" rel="stylesheet">

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		//获取全部
		allAemindContract();
		
		//选中获取
		var cid;
		var sid;
		var modal;
		var name;
		var time;
		var isRequest;
		
	});
	function allAemindContract(){
		var options = {
    			url: "/coach/allContract",
    			method: 'post',
    			data:{
    				//假设当前教练id为1
    				"currentUid":1
			    },
			    success: function (data) {
			    	console.info(data);
			    	var po = "";
			    	if (data!=null) {
				    	var ac = data.contract;
				    	var st = data.student;
				    	for (var i = 0; i < ac.length; i++) {
				    		po = '<tr onclick=getThisRow(this)>'
				    			+'<td hidden>'+ac[i].cid+'</td>'
				    			+'<td hidden>'+ac[i].sid+'</td>'
					    		+'<td>'+st.sname+'</td>'
					    		+'<td>'+ac[i].createDate+'</td>'
					    		+'<td>'+ac[i].status+'</td>'
					    		+'</tr>';
						}
					}
			    	$("#allContract").html(po);
			    }
    	};
    	$.ajax(options);
	}
	//操作选中行
	function getThisRow(element) {
		cid = element.children[0].innerHTML;
		sid = element.children[1].innerHTML;
		name = element.children[2].innerHTML;
		time = element.children[3].innerHTML;
		//弹窗
		modal = document.getElementById('myModal');
		var span = document.querySelector('.close');
		modal.style.display = "block";
		span.onclick = function() {
		    modal.style.display = "none";
		}
		window.onclick = function(event) {
		    if (event.target == modal) {
		        modal.style.display = "none";
		    }
		}
		//检验是否有效请求
		var options = {
    			url: "/coach/checkStatus",
    			method: 'post',
    			data:{
    				"time":time
			    },
			    success: function (data) {
			    	console.info(data);
			    	isRequest = data;
			    	//请求是否有效
					$(".modal-header-content").html(data);			    	
			    }
    	};
    	$.ajax(options);
		//姓名
		//$(".modal-body-content").html(name);
	}
	//接受
	function adopt(){
		var options = {
    			url: "/coach/alterStatus_adopt",
    			method: 'post',
    			data:{
    				"cid":cid,
    				"sid":sid,
    				"isRequest":isRequest
			    },
			    success: function (data) {
			    	console.info(data);
			    	alert(data);
			    	modal.style.display = "none";
			    	//刷新全部
					allAemindContract();
			    }
    	};
    	$.ajax(options); 
	}
	//拒绝
	function refuse(){
		var options = {
    			url: "/coach/alterStatus_refuse",
    			method: 'post',
    			data:{
    				"cid":cid,
    				"sid":sid,
    				"isRequest":isRequest
			    },
			    success: function (data) {
			    	console.info(data);
			    	alert(data);
			    	modal.style.display = "none";
			    	//刷新全部
					allAemindContract();
			    }
    	};
    	$.ajax(options);
	} 	
			

</script>
</head>
<body>
<!-- <div class="container"> -->
<div class="layui-container" style="width: 60%;height: 720px;">
		<!-- 导航栏 -->
		<ul class="layui-nav">
		  <li class="layui-nav-item">
		   <!-- 	<a href="../home.jsp" id="totle">Yoga</a> -->
		   	<a href="../home.jsp" style="font-family: 'Tangerine', cursive;font-size: 100%;color:white;">Yoga</a>
		  </li>
		  <li class="layui-nav-item" style="float: right;">
		    <a href="#" onClick="javascript :history.back(-1);">返回</a>
		  </li>
		</ul>

	<div style="margin-bottom: 15px;">
		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			<legend>签约通知</legend>
		</fieldset>
	</div>

<!-- 	<p class="bg-light" id="order">签约通知</p> -->
	<table class="layui-table">
	  <colgroup>
	    <col width="20%">
	    <col width="30%">
	    <col width="40%">
	  </colgroup>
	  <thead>
	    <tr>
	      <th>姓名</th>
	      <th>时间</th>
	      <th>状态</th>
	    </tr> 
	  </thead>
	  <tbody id="allContract">
	    <!-- 显示内容 -->
	  </tbody>
	</table>
</div>
	
<!-- 弹窗 -->
<div id="myModal" class="modal">
	<div class="container">
	  	<!-- 弹窗内容 -->
	    <div class="modal-content">
	      <div class="modal-header">
	        <span class="close">&times;</span>
	        <br>
	        <p class="modal-header-content">header</p>
	        <br>
	      </div>
	      <div class="modal-body">
	      	<br>
	        <p class="modal-body-content">
	        	<!-- 弹窗文本 -->
	        </p>
	        <br>
	      </div>
	      <div class="modal-footer"><br>
	        <button class="layui-btn layui-btn-sm layui-btn-normal" onclick="adopt()">接受</button>
	        <button class="layui-btn layui-btn-sm layui-btn-normal" onclick="refuse()">拒绝</button><br><br>
	      </div>
	    </div>
    </div>
</div>
	
</body>
</html>